package com.gourd.index.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author gourd
 */
@Configuration
@EnableSwagger2
@ConditionalOnProperty(name = "swagger.gourd.enabled", havingValue = "true")
public class Swagger2Config {
    @Bean
    public Docket smallGourdCommon() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("gourd-common接口文档")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.gourd.common.controller"))
                .paths(PathSelectors.any()).build();
    }
    @Bean
    public Docket smallGourdQuartz() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("gourd-quartz接口文档")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.gourd.quartz.controller"))
                .paths(PathSelectors.any()).build();
    }
    @Bean
    public Docket smallGourdNotice() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("gourd-notice接口文档")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.gourd.notice.controller"))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket smallGourdFile() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("gourd-file接口文档")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.gourd.file.controller"))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket smallGourdWeb() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("gourd-web接口文档")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.gourd.web.controller"))
                .paths(PathSelectors.any()).build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("smallGourd系统")
                .description("smallGourd")
                .termsOfServiceUrl("https://blog.csdn.net/HXNLYW")
                .contact(new Contact("smallGourd ", "https://blog.csdn.net/HXNLYW", "13584278267@163.com"))
                .version("1.0.0").build();
    }
}